package com.javademo.maptest;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public class ConcurrentHashMapTest {
    public static void main(String[] args) {

        HashMap<Integer, String> hashMapTest = new HashMap<>();
        hashMapTest.put(8, "x");
        hashMapTest.put(9, "y");
        ConcurrentHashMap<Integer, String> concurrentHashMapTest = new ConcurrentHashMap<>(hashMapTest);
        putTest(concurrentHashMapTest);
        log.info("concurrentHashMapTest: {}", concurrentHashMapTest);
        concurrentHashMapTest.forEach(4, (k, v) -> v, v -> log.info("v: {}", v));
    }

    private static void putTest(ConcurrentHashMap<Integer, String> concurrentHashMapTest){
        concurrentHashMapTest.put(1, "a");
        concurrentHashMapTest.put(2, "b");
        concurrentHashMapTest.put(3, "c");
        concurrentHashMapTest.put(4, "d");
        concurrentHashMapTest.put(5, "e");
    }
}
